package com.xbongbong.workflow.domain.dao;

import com.xbongbong.workflow.domain.entity.WorkflowNodeEntity;
import com.xbongbong.workflow.domain.entity.ext.WorkflowNodeEntityExt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface WorkflowNodeDao {
    Integer insert(WorkflowNodeEntity entity);

    void insertBatch(List<WorkflowNodeEntity> list);

    void insertExtBatch(List<WorkflowNodeEntityExt> list);

    WorkflowNodeEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid );
    
    WorkflowNodeEntityExt getExtByKey(@Param("key") Long key, @Param("corpid") String corpid );

    Integer update(WorkflowNodeEntity entity);

    List<WorkflowNodeEntity> findEntities(@Param("param") Map<String, Object> param);

    Integer getEntitiesCount(@Param("param") Map<String, Object> param);

    /**
     * 获取实体
     * @param workflowId
     * @param prevId
     * @param corpid
     * @return com.xbongbong.workflow.domain.entity.WorkflowNodeEntity
     * @author 吴峰
     * @date 2021/5/12 10:30
     */
    List<WorkflowNodeEntity> getByWorkflowIdAndPrevId(@Param("workflowId") Long workflowId, @Param("prevId")String prevId, @Param("corpid")String corpid);
    /**
     * 删除节点
     * @param key
     * @param corpid
     * @return
     */
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid );
    /**
     * 批量删除
     * @param idIn
     * @param corpid
     * @return
     */
    Integer deleteBatch(@Param("idIn") Collection<Long> idIn, @Param("corpid")String corpid);
    /**
     * 删除工作流下的所有节点
     * @param workflowId
     * @param corpid
     * @return
     */
    Integer deleteByWorkflowId(@Param("workflowIdList")List<Long> workflowId,@Param("corpid") String corpid);
    /**
     * 获取实体
     * @param uId
     * @param workflowId
     * @param corpid
     * @return com.xbongbong.workflow.domain.entity.WorkflowNodeEntity
     * @author 吴峰
     * @date 2021/5/18 15:00
     */
    WorkflowNodeEntity getByUId(@Param("workflowId") Long workflowId, @Param("uId")String uId, @Param("corpid")String corpid);
    
    List<WorkflowNodeEntityExt> list(@Param("param") Map<String, Object> param);

    /**
     * 批量编辑块id
     * @param list
     * @param corpid
     * @return java.lang.Integer
     * @author 吴峰
     * @date 2021/5/26 16:19
     */
    Integer updateWrapperId(@Param("list") List<WorkflowNodeEntity> list,@Param("corpid") String corpid);

    Integer sort(@Param("list") List<WorkflowNodeEntity> nodeList,@Param("corpid") String corpid);

    /**
     * 更新wrapperId
     * wrapperId 未判空，请谨慎使用
     * @param list
     * @param wrapperId
     * @param corpid
     * @return
     */
    Integer updateWrapperIdByIdIn(@Param("list")List<Long> list, @Param("wrapperId") String wrapperId,@Param("corpid") String corpid);

    /**
     * 批量编辑配置
     * @param list
     * @param corpid
     */
    void updateConfigData(@Param("list") List<? extends WorkflowNodeEntity> list,@Param("corpid") String corpid);

    /**
     * 批量编辑
     * @param updateList
     * @param corpid
     * @return
     */
    Integer updatePrevIdBatch(@Param("list") List<WorkflowNodeEntity> updateList, @Param("corpid") String corpid);
}